from rest_framework.serializers import ModelSerializer

from course.models import Category, Course, Teacher
from drf_haystack.serializers import HaystackSerializer
from course import search_indexes

class CateForySer(ModelSerializer):
    class Meta:
        model = Category
        fields = "__all__"
class CateGorySer(ModelSerializer):
    children = CateForySer(many=True)
    class Meta:
        model = Category
        fields = "__all__"
class CourseSer(ModelSerializer):
    class Meta:
        model = Course
        fields = "__all__"
class TeacherSer(ModelSerializer):
    class Meta:
        model = Teacher
        fields=['id','name','headimg','intro','job']
class CourseDetailSer(ModelSerializer):
    teacher = TeacherSer()
    class Meta:
        model = Course
        fields = "__all__"

#索引序列化器

class CourseIndexSerializer(HaystackSerializer): #继承
    class Meta:
        index_classes = [search_indexes.CourseIndex] #指定索引类
        fields = ['id','cname','price','discount','introduction','cover','text']
